<?php

/******************************************************************************
 *
 *	PROJECT: Flynax Classifieds Software
 *	VERSION: 4.0
 *	LISENSE: FL87MPRYOA0R - http://www.flynax.com/license-agreement.html
 *	PRODUCT: Auto Classifieds
 *	DOMAIN: www.siyaradiali.com
 *	FILE: REQUEST.PHP
 *
 *	This script is a commercial software and any kind of using it must be 
 *	coordinate with Flynax Owners Team and be agree to Flynax License Agreement
 *
 *	This block may not be removed from this file or any other files with out 
 *	permission of Flynax respective owners.
 *
 *	Copyrights Flynax Classifieds Software | 2012
 *	http://www.flynax.com/
 *
 ******************************************************************************/

/* load configs */
include_once( dirname(__FILE__) . "/../../includes/config.inc.php");

/* system controller */
require_once( RL_INC . 'control.inc.php' );

$mode = $_GET['mode'];

if ( $mode == 'wf' )
{
	$woeid = $_GET['w'];
	$units = $_GET['u'];
	$url = "http://weather.yahooapis.com/forecastrss?w={$woeid}&u={$units}";
	
	if ( $woeid && $units )
	{
		$content = $reefless -> getPageContent($url);
		
		if ( $content )
		{
			$reefless -> loadClass('WeatherForecast', null, 'weatherForecast');
			
			/* parse location */
			$location = $rlWeatherForecast -> parse($content, 'yweather:location', true, array('city', 'region', 'country'));
			$response['location'] = $location;
			
			/* parse condition */
			$location = $rlWeatherForecast -> parse($content, 'yweather:condition', true, array('text', 'code', 'temp', 'date'));
			$response['condition'] = $location;
			
			/* parse forecast */
			$location = $rlWeatherForecast -> parse($content, 'yweather:forecast', true, array('day', 'date', 'low', 'high', 'text', 'code'));
			$response['forecast'] = $location;
	
			$reefless -> loadClass( 'Json' );
		
			$output['total'] = count($response);
			$output['data'] = $response;
		
			echo $rlJson -> encode( $output );
		}
	}
	else
	{
		echo false;
	}
}
elseif ( $mode == 'query' )
{
	$query = $_GET['query'];
	
	if ( !empty($query) )
	{
		$query = urlencode($query);
		$url = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22{$query}%22&format=xml";
		$content = $reefless -> getPageContent($url);
		
		if ( $content )
		{
			$reefless -> loadClass('WeatherForecast', null, 'weatherForecast');
			
			/* parse forecast */
			$woeid = $rlWeatherForecast -> parse($content, 'woeid', false);
			$response['woeid'] = $woeid;
	
			$reefless -> loadClass( 'Json' );
		
			$output['total'] = count($response);
			$output['data'] = $response;
		
			echo $rlJson -> encode( $output );
		}
	}
}